#include "TextField.h"

TextField::TextField()
	: m_IsVisible(true), m_Bkg(0)
{

}

TextField::TextField(SDLSprite* _bkg, bool _visible)
	: m_IsVisible(_visible), m_Bkg(_bkg)
{

}

TextField::TextField(int _posX, int _posY, int _frameX, int _frameY, int _width, int _height, std::string _fileName, SDLScene* _scene, bool _visible)
	: m_IsVisible(_visible), m_Bkg(0)
{
	m_Bkg = new SDLSprite(_posX, _posY, _frameX, _frameY, _width, _height, _fileName, _scene);
}

TextField::~TextField()
{
	std::vector<SDLText*>::iterator iter;

	for(iter = m_Texts.begin(); iter != m_Texts.end(); iter++)
	{
		iter = m_Texts.erase(iter);
	}

	delete m_Bkg;
	m_Bkg = 0;
}

void TextField::AddText(SDLText* _text)
{
	m_Texts.push_back(_text);
}

void TextField::SetVisible(bool _visible)
{
	std::vector<SDLText*>::iterator iter;
	
	for(iter = m_Texts.begin(); iter != m_Texts.end(); iter++)
	{
		(*iter)->SetVisible(_visible);
	}

	m_Bkg->SetVisible(_visible);
	m_IsVisible = _visible;
}

void TextField::SetBackground(SDLSprite* _bkg)
{
	delete m_Bkg;
	m_Bkg = _bkg;
}